using System;
using Glue;
using Glue.Internals.Verification;
using Xunit;

namespace GlueTests.MapperVerificationTests
{
    public class When_mapping_throws_exception
    {
        private readonly Mapping<DomainPerson, GuiPerson> mapping;
        private readonly MapperVerification<DomainPerson, GuiPerson> verification;

        public class DomainPerson { public String FirstName { get { return ""; } set { throw new Exception("DomainPerson fails the set"); } } }
        public class GuiPerson { public String FirstName { get{ return "";} set {throw new Exception("GuiPerson fails the set");} } }

        public When_mapping_throws_exception()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
            verification = new MapperVerification<DomainPerson, GuiPerson>(mapping);
            mapping.AutoRelateEqualNames();
        }

        [Fact]
        public void Should_throw_informative_exception()
        {
            Assert.Throws(typeof(GlueException), ()=> verification.AssertMapsCorrectlyTowards(new GuiPerson()));
            Assert.Throws(typeof(GlueException), ()=> verification.AssertMapsCorrectlyTowards(new DomainPerson()));
        }    
    }
}